package edu.nanyang.controller;

import edu.nanyang.domain.AcademyInfo;
import edu.nanyang.service.AcademyInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/admin/academy")
public class AcademyInfoController extends BaseController{
    @Resource
    private AcademyInfoService academyInfoService;

    @GetMapping("/delete")
    public String delete(int id){
        int result=academyInfoService.delete(id);
        if(result>0){
            request.setAttribute("tip_info","删除学院信息成功！");
        }else{
            request.setAttribute("tip_info","删除学院信息失败！");
        }
        return "forward:findall";
    }
    @GetMapping("/findall")
    public String findAll(){
        List<AcademyInfo> academyInfoList=academyInfoService.findAll();
        request.setAttribute("academy_info",academyInfoList);
        return "admin/academy/academy_list";
    }

    @GetMapping("/addpage")
    public String addPage(){
        return "admin/academy/academy_add";
    }

    @PostMapping("/addsave")
    public String addSave(AcademyInfo academyInfo){
        int result=academyInfoService.add(academyInfo);
        if(result>0){
            request.setAttribute("tip_info","添加学院信息成功！");
        }else{
            request.setAttribute("tip_info","添加学院信息失败！");
        }
        return "result";
    }

    @GetMapping("/updatepage")
    public String updatePage(int id){
        AcademyInfo academyInfo=academyInfoService.getById(id);
        request.setAttribute("academy_info",academyInfo);
        return "admin/academy/academy_edit";
    }
    @PostMapping("/updatesave")
    public String updateSave(AcademyInfo academyInfo){
        int result=academyInfoService.update(academyInfo);
        if(result>0){
            request.setAttribute("tip_info","修改学院信息成功！");
        }else{
            request.setAttribute("tip_info","修改学院信息失败！");
        }
        return "result";
    }








}
